# Program variables (DON'T DELETE!!!)
block_speed = -6 # controls how fast the pipes move across the stage
block_gap = 200 # controls the space between the top and bottom of each pipe
block_interval = 1 # controls how often a new pipe appears
gravity = 8 # controls how fast the sprite falls
flappiness = 5 # controls how much the sprite moves up
# Store and display score
score = 0
score_text = codesters.Text("Score: " + str(score), 100, 200, "yellow")
########################################################################
# ADD CODE BELOW THIS LINE #
########################################################################
stage.set_background("space")
stage.disable_all_walls()
sprite = codesters.Sprite("dinosaur")
sprite.set_size(0.4)
sprite.set_say_color("yellow")
sprite.say("TAP THE SPACE BAR TO GUIDE ME THROUGH THE BLOCKS!", 3)
sprite.go_to(-200, 0)
stage.set_gravity(gravity)
def space_bar():
sprite.jump(flappiness)
stage.event_key("space", space_bar)
def interval():
global score
score += 1
score_text.set_text("Score: " + str(score))
make_blocks()
stage.event_interval(interval, block_interval)
def make_blocks():
pass # delete after adding indented code
y1 = random.randint(-250, -100)
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(0, 0, 100, 50, "blue")
t = codesters.Teacher()
rectangles = t.find_function("Rectangle")
set_gravity_offs = t.find_function("set_gravity_off")
set_x_speeds = t.find_function("set_x_speed")
try:
tval1 = rectangles[0][1].lower().replace(' ','')
tval1_indent = t.get_indent_at_line(rectangles[0][0])
except:
tval1 = "DNE"
tval1_indent = "DNE"
try:
tval2 = set_gravity_offs[0][1].lower().replace(' ','')
tval2_indent = t.get_indent_at_line(set_gravity_offs[0][0])
except:
tval2 = "DNE"
tval2_indent = "DNE"
try:
tval3 = set_x_speeds[0][1].lower().replace(' ','')
tval3_indent = t.get_indent_at_line(set_x_speeds[0][0])
except:
tval3 = "DNE"
tval3_indent = "DNE"
t1 = TestObjective()
t1.add_success('(250,y1,100,300,"red")' in tval1, "Great Job!")
t1.add_failure(tval1 == "DNE", "Oops, did you delete the rectangle?")
t1.add_failure(tval1 != "DNE" and '(250,y1,100,300,"red")' not in tval1, "Did you change the arguments for the rectangle?")
t2 = TestObjective()
t2.add_success(tval2 != "DNE" and tval2_indent == 4, "Great job!")
t2.add_failure(tval2 == "DNE", "Did you add Sprite Gravity Off inside the make_blocks() function?")
t2.add_failure(tval2 != "DNE" and tval2_indent != 4, "Make sure Sprite Gravity Off is indented once inside make_blocks()!")
t3 = TestObjective()
t3.add_success('(block_speed)' in tval3 and tval3_indent == 4, "Great job!")
t3.add_failure(tval3 == "DNE", "Did you add Set x Speed inside the make_blocks() function?")
t3.add_failure(tval3 != "DNE" and '(block_speed)' not in tval3, "Did you change the x speed from 5 to the variable block_speed?")
t3.add_failure(tval3 != "DNE" and tval3_indent != 4, "Make sure Set x Speed is indented one time inside make_blocks()!")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()